<?php
class m_log_adik_asuh extends Model{
    var $table = "log_adik_asuh";
    
    function getCountRows($params){
        $where = "";
        if($params['awal'] != "" && $params['akhir']){
            $where .= "and tanggal between '$params[awal]' and '$params[akhir]'";
        }
        if($params['idAdikAsuh'] != ""){
            $where .= " and id_adik_asuh = '$params[idAdikAsuh]'";
        }
        $query = $this->db->query("select * from log_adik_asuh where id_member = '".$this->session->userdata('id_member')."' $where");
        
        return $query->num_rows();
    }
    function getListLogAdikAsuh($offset = NULL,$limit = NULL,$params){
        $where = "";
        if($params['awal'] != "" && $params['akhir']){
            $where .= " where l.tanggal between '$params[awal]' and '$params[akhir]'";
        }
        if($params['idAdikAsuh'] != ""){
            $where .= " and l.id_adik_asuh = '$params[idAdikAsuh]'";
        }
        if($params['idTahunAjaran'] != ''){
            $where .= " and l.id_tahun_ajaran = '$params[idTahunAjaran]'";
        }
        if($offset != NULL || $limit != NULL){
            $limits = "limit $offset,$limit";
        }else $limits = '';
        
        $query = $this->db->query("select l.tanggal,l.komentar,m.nama as member,a.nama as adik_asuh,s.nama as sekolah,k.nama as kelas,ta.nama as tahun_ajaran,sms.nama as semester from log_adik_asuh l
                  join member m on l.id_member = m.id
                  join adik_asuh a on l.id_adik_asuh = a.id
                  join sekolah s on l.id_sekolah = s.id
                  join kelas k on l.id_kelas = k.id
                  join tahun_ajaran ta on l.id_tahun_ajaran = ta.id
                  join semester sms on ta.id_semester = sms.id
                  $where $limits");
        //where l.id_member = '".$this->session->userdata('id_member')."'
        if($query->num_rows() > 0){
            return $query->result_array();
        }else return array();
    }
    function add_log_adik_asuh($data){
        $insert = $this->db->insert($this->table,$data);
        if($insert){
            return TRUE;
        }else return FALSE;
    }
}
?>
